package it.antonio.ilpizze.db.core.id;

import it.antonio.ilpizze.db.DbException;

public class MemoryTableId implements FilePositionId{

	private boolean persisted;
	private long position = -1;
	
	private MemoryTableId() {
	}

	public void persisted(long position) {
		this.persisted = true;
		this.position = position;
	}
	public boolean isPersisted() {
		return persisted;
	}
	@Override
	public long pos() {
		if(persisted == false) throw new DbException("MemoryTableId not persisted yet");
		return position;
	}

	@Override
	public boolean equals(Object o) {
		if(this == o) return true;
		if(o instanceof MemoryTableId){
			MemoryTableId another = (MemoryTableId) o;
			
			if(another.persisted == persisted && another.position == position) {
				return true;
			}
		}
		return false;
	}
	
	public static MemoryTableId create(){
		return new MemoryTableId();
	}

	
}
